package com.bytz.modules.system.controller;


import com.bytz.common.api.vo.Result;
import com.bytz.common.system.api.ISysBaseApi;
import com.bytz.common.system.vo.DictModel;
import com.bytz.modules.system.service.ISysDictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 字典表 前端控制器
 * </p>
 *
 * @Author zhangweijian
 * @since 2018-12-28
 */
@RestController
@RequestMapping("/sys/dict")
@Slf4j
public class SysDictController {

    @Autowired
    private ISysDictService sysDictService;

    @Autowired
    private ISysBaseApi sysBaseApi;

    /**
     * 获取字典数据
     *
     * @param dictCode 字典code
     * @return 字典内容
     */
    @RequestMapping(value = "/getDictItems/{dictCode}", method = RequestMethod.GET)
    public Result<List<DictModel>> getDictItems(@PathVariable String dictCode) {
        return Result.ok(sysBaseApi.queryAvailableDictItemsByCode(dictCode));
    }

    /**
     * 获取字典数据
     *
     * @param dictCode 编码
     * @param key 键
     * @return 值
     */
    @RequestMapping(value = "/getDictText/{dictCode}/{key}", method = RequestMethod.GET)
    public Result<String> getDictItems(@PathVariable("dictCode") String dictCode, @PathVariable("key") String key) {

        return Result.ok("操作成功", sysDictService.queryDictTextByKey(dictCode, key));
    }
}
